/*********
*******作者：胡鼎文
*******时间：2012-2-26
*******版本：未压缩
*********/
//定义弹出层类
     function Popup(id,width,height,content,isClose,showTime,lastTime){
        //定义属性
        this.id=id;
        this.width=width;
        this.height=height;
        this.content=content;
        this.isClose=isClose;
        //this.showTime=showTime;
        this.lastTime=lastTime;
        //定义creatediv方法
      Popup.prototype.creatediv=function(){           
        var popdiv=document.createElement("div");
        popdiv.innerHTML="<a id='closeIcon' href='javascript:Popup.prototype.closediv()' style='display:block;width:100%;height:24px;position:absolute;top:-24px;text-decoration:none;text-align:right;color:#fff'>关闭</a>";
        popdiv.id=this.id;    
        popdiv.style.position="absolute";
        popdiv.style.backgroundColor="#fff";
        popdiv.style.border="1px";
        popdiv.style.borderStyle="solid";
        popdiv.style.borderColor="#ccc";
        popdiv.style.width=this.width+"px";
        popdiv.style.height=this.height+"px";
        popdiv.style.zIndex="10001";
        document.body.appendChild(popdiv);
        
         /*定义弹出层的居中位置*/
        var mydiv=document.getElementById(this.id);
        var mydiv_w=Popup.getStyle(mydiv,"width");
        var mydiv_h=Popup.getStyle(mydiv,"height");
    
        mydiv_w=parseInt(mydiv_w);
        mydiv_h=parseInt(mydiv_h);
     
        var width=Popup.pageWidth();
        var height=Popup.pageHeight();
        var left=Popup.leftPosition();
        var top=Popup.topPosition();
     
        var div_topposition=top+(height/2)-(mydiv_h/2);
        var div_leftposition=left+(width/2)-(mydiv_w/2);
     
        mydiv.style.left=div_leftposition+"px";
        mydiv.style.top=div_topposition+"px";
        mydiv.style.display="block";
        Popup.backdiv();
        /*定义弹出层的内容*/
        var contentdiv=document.createElement("div");
        contentdiv.id="contentId";
        contentdiv.innerHTML=this.content;
        popdiv.appendChild(contentdiv);
        /*定义是否自动消失*/
        if(!this.isClose){
           this.isClose=false;
        }
        else{
           if(this.isClose==true)
           {
             setTimeout(Popup.closediv,this.lastTime);
             
           }
           else
           {
             return -1;
           }
        }
    }
   

   /*定义关闭弹出层的方法*/
     Popup.prototype.closediv=function(){
        var Backdiv=document.getElementById("Backdiv");
        var closeIcon=document.getElementById("closeIcon");//获取关闭按钮
        var parentdiv=closeIcon.parentNode;
        $('#Backdiv').fadeOut('slow');
        function det(){
            $('#Backdiv').detach('#Backdiv');
        }
        setTimeout(det,5000);
        //document.body.removeChild(Backdiv);//关闭背景层
        document.body.removeChild(parentdiv);//关闭弹出层
        //Backdiv.style.display="none";
        //parentdiv.style.display="none";
        Popup.SetCookie("closediv","closediv",2);
       
    }
    

     
   /*定义背景层方法*/
     Popup.backdiv=function(){
        var sWidth,sHieght;
        sWidth=window.screen.availWidth;
        //屏幕可用工作区高度 window.screen.availHeight;
        //屏幕可用工作区宽度 window.screen.availWidth;
        //网页的正文全文高度 document.body.scrollHeight;
        //网页的正文全文宽度 document.body.scrollWidth;
        if(window.screen.availHeight>document.body.scrollHeight)//当高度小于一屏
        {
        sHeight=window.screen.availHeight;
        }
        else//当高度大于一屏幕
        {
        sHeight=document.body.scrollHeight;
        }
        var markobj=document.createElement("iframe");
        //markobj.setAttribute("id","Backdiv");
        markobj.id="Backdiv";  
        markobj.style.position="absolute";
        markobj.style.top="0";
        markobj.style.left="0";
        markobj.style.filter="Alpha(opacity=30)";
        markobj.style.opacity="0.3";
        markobj.style.width=sWidth+"px";
        markobj.style.height=sHeight+"px";
        markobj.style.zIndex="10000";
        markobj.src='js/nothing.htm';//空白页，用于设置背景色
        document.body.appendChild(markobj);
      
   }
// 计算当前窗口的宽度 //
     Popup.pageWidth=function(){
			 return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// 计算当前窗口的高度 //
     Popup.pageHeight=function(){
			 return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// 计算当前窗口的上边滚动条//
     Popup.topPosition=function(){
			  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// 计算当前窗口的左边滚动条//
     Popup.leftPosition=function(){
			 return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

//解决外嵌样式style , 用js获取不到的问题。
   Popup.getStyle=function(elem, name){
			if(elem.style[name])
				return elem.style[name];
			else if(elem.currentStyle)	//ie
				return elem.currentStyle[name];
			else if(document.defaultView && document.defaultView.getComputedStyle){	//w3c
				name = name.replace(/([A-Z])/g,"-$1");
				name = name.toLowerCase();
				
				var s = document.defaultView.getComputedStyle(elem,"");
				return s && s.getPropertyValue(name);
			} else
				return null
     }
   /*设置cookie函数*/
   Popup.SetCookie=function(name, value,days)   {   
     var expire_time = days*24*3600*1000//(保存的天数)   
     var expire_date = new Date();//长期有效的办法   
     var ms_from_now = expire_time;   
     expire_date.setTime(expire_date.getTime() + ms_from_now);   
     var expire_string = expire_date.toGMTString();   
     document.cookie = name + "=" + escape(value)+ ";expires=" +expire_string;   
  }   

}  
   
   /*获取cookie函数*/
   function get_cookie(Name) {
     var search = Name + "="
     var returnvalue = "";
     if (document.cookie.length > 0) {
     offset = document.cookie.indexOf(search)
     if (offset != -1) {
       offset += search.length
       end = document.cookie.indexOf(";", offset);
       if (end == -1)
       end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
     }
    return returnvalue;
}


  